package cn.tedu.csmall.server.controller;
 /*
 @Time: 2022/8/25 18:16
 @Author:GShuai
 @File:AttribuTetemplateController.class
 @Software:IntelliJ IDEA
*/



import cn.tedu.csmall.server.pojo.dto.AttributeTemplateAddNewDTO;
import cn.tedu.csmall.server.pojo.vo.AttributeTemplateListItemVO;
import cn.tedu.csmall.server.service.IAttributeTemplateService;
import cn.tedu.csmall.server.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "5. 属性模板管理模块")
@RequestMapping("/attribute-templates")
@RestController
public class AttributeTemplateController {


    @Autowired
    private IAttributeTemplateService attributeTemplateService;

    public AttributeTemplateController() {
        log.debug("创建控制器对象：AttributeTemplateController");
    }

    // http://localhost:9080/attributes-templates/add-new
    @ApiOperation("添加属性模板")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult addNew(@RequestBody AttributeTemplateAddNewDTO attributeTemplateAddNewDTO) {
        log.debug("接收到的请求参数：{}", attributeTemplateAddNewDTO);
        attributeTemplateService.addNew(attributeTemplateAddNewDTO);
        return JsonResult.ok();
    }

    // http://localhost:9080/attributes-templates/12/delete
    @ApiOperation("删除属性模板")
    @ApiOperationSupport(order = 200)
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult delete(@PathVariable Long id) {
        attributeTemplateService.deleteById(id);
        return JsonResult.ok();
    }

    // http://localhost:9080/attributes-templates
    @ApiOperation("查询属性模板列表")
    @ApiOperationSupport(order = 400)
    @GetMapping("")
    public JsonResult list() {
        log.debug("接收到查询属性列表的请求");
        List<AttributeTemplateListItemVO> attributes = attributeTemplateService.list();
        return JsonResult.ok(attributes);
    }
}
